home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / circuits / irsim-9.000 / irsim-9 / src / irsim / parallel.c < prev    next >
C/C++ Source or Header  |  1993-01-15  |  6KB  |  223 lines

  1. /* 
  2.  *     ********************************************************************* 
  3.  *     * Copyright (C) 1988, 1990 Stanford University.                     * 
  4.  *     * Permission to use, copy, modify, and distribute this              * 
  5.  *     * software and its documentation for any purpose and without        * 
  6.  *     * fee is hereby granted, provided that the above copyright          * 
  7.  *     * notice appear in all copies.  Stanford University                 * 
  8.  *     * makes no representations about the suitability of this            * 
  9.  *     * software for any purpose.  It is provided "as is" without         * 
  10.  *     * express or implied warranty.  Export of this software outside     * 
  11.  *     * of the United States of America may require an export license.    * 
  12.  *     ********************************************************************* 
  13.  */
  14.  
  15. #include <stdio.h>
  16. #include "defs.h"
  17. #include "net.h"
  18. #include "globals.h"
  19.  
  20. #include "net_macros.h"
  21.  
  22.  
  23. private int    nored[ NTTYPES ];
  24.  
  25. #define    hash_terms( T )        ( (Ulong)((T)->source) ^ (Ulong)((T)->drain) )
  26.  
  27. #define    COMBINE( R1, R2 )    ( ((R1) * (R2)) / ((R1) + (R2)) )
  28.  
  29.  
  30. typedef struct
  31.   {
  32.     float    dynres[ 2 ];
  33.     float    rstatic;
  34.   } TranResist;
  35.  
  36.  
  37. /*
  38.  * Run through the list of nodes, collapsing all transistors with the same
  39.  * gate/source/drain into a compound transistor.
  40.  * As a side effect, if stack_txtors is set clear the VISITED bit on all 
  41.  * nodes on the list.
  42.  */
  43. public void make_parallel( nlist )
  44.   register nptr  nlist;
  45.   {
  46.     register nptr   n;
  47.     register lptr   l1, l2, prev;
  48.     register tptr   t1, t2;
  49.     register Ulong  hval;
  50.     register int    type;
  51.     register long   cl;
  52.  
  53.     cl = (stack_txtors) ? 0 : VISITED;
  54.     for( cl = ~cl; nlist != NULL; nlist->nflags &= cl, nlist = nlist->n.next )
  55.       {
  56.     for( l1 = nlist->nterm; l1 != NULL; l1 = l1->next )
  57.       {
  58.         t1 = l1->xtor;
  59.         type = t1->ttype;
  60.         if( type & (GATELIST | ORED) )
  61.         continue;    /* ORED implies processed, so skip as well */
  62.  
  63.         hval = hash_terms( t1 );
  64.         prev = l1;
  65.         for( l2 = l1->next; l2 != NULL; prev = l2, l2 = l2->next )
  66.           {
  67.         t2 = l2->xtor;
  68.         if( t1->gate != t2->gate or hash_terms( t2 ) != hval or 
  69.           type != (t2->ttype & ~ORED) )
  70.             continue;
  71.  
  72.         if( not (t1->ttype & ORED) )
  73.           {
  74.             NEW_TRANS( t2 );
  75.             t2->r = (Resists *) Falloc( sizeof( TranResist ), 1 );
  76.             t2->r->dynlow = t1->r->dynlow;
  77.             t2->r->dynhigh = t1->r->dynhigh;
  78.             t2->r->rstatic = t1->r->rstatic;
  79.             t2->gate = t1->gate;
  80.             t2->source = t1->source;
  81.             t2->drain = t1->drain;
  82.             t2->ttype = (t1->ttype & ~ORLIST) | ORED;
  83.             t2->state = t1->state;
  84.             t2->tflags = t1->tflags;
  85.             t2->tlink = t1;
  86.             t1->scache.t = NULL;
  87.             t1->dcache.t = t2;
  88.             REPLACE( t1->gate->ngate, t1, t2 );
  89.             REPLACE( t1->source->nterm, t1, t2 );
  90.             REPLACE( t1->drain->nterm, t1, t2 );
  91.             t1->ttype |= ORLIST;
  92.             t1 = t2;
  93.             t2 = l2->xtor;
  94.             nored[ BASETYPE( t1->ttype ) ]++;
  95.           }
  96.  
  97.           {
  98.             register Resists  *r1 = t1->r, *r2 = t2->r;
  99.  
  100.             r1->rstatic = COMBINE( r1->rstatic, r2->rstatic );
  101.             r1->dynlow = COMBINE( r1->dynlow, r2->dynlow );
  102.             r1->dynhigh = COMBINE( r1->dynhigh, r2->dynhigh );
  103.           }
  104.  
  105.         DISCONNECT( t2->gate->ngate, t2 );    /* disconnect gate */
  106.         if( t2->source == nlist )        /* disconnect term1 */
  107.             DISCONNECT( t2->drain->nterm, t2 )
  108.         else
  109.             DISCONNECT( t2->source->nterm, t2 );
  110.  
  111.         prev->next = l2->next;            /* disconnect term2 */
  112.         FREE_LINK( l2 );
  113.         l2 = prev;
  114.  
  115.         if( t2->ttype & ORED )
  116.           {
  117.             register tptr  t;
  118.  
  119.             for( t = t2->tlink; t->scache.t != NULL; t = t->scache.t )
  120.             t->dcache.t = t1;
  121.             t->scache.t = t1->tlink;
  122.             t1->tlink = t2->tlink;
  123.  
  124.             Ffree( t2->r, sizeof( TranResist ) );
  125.             FREE_TRANS( t2 );
  126.           }
  127.         else
  128.           {
  129.             t2->ttype |= ORLIST;    /* mark as part of or */
  130.             t2->dcache.t = t1;        /* this is the real txtor */
  131.             t2->scache.t = t1->tlink;    /* link unto t1 list */
  132.             t1->tlink = t2;
  133.             nored[ BASETYPE( t1->ttype ) ]++;
  134.           }
  135.           }
  136.       }
  137.       }
  138.   }
  139.  
  140.  
  141. public void UnParallelTrans( t )
  142.   register tptr  t;
  143.   {
  144.     tptr    tor;
  145.     double  dr;
  146.  
  147.     if( not (t->ttype & ORLIST) )
  148.     return;                /* should never be */
  149.  
  150.     tor = t->dcache.t;
  151.     if( tor->tlink == t )
  152.     tor->tlink = t->scache.t;
  153.     else
  154.       {
  155.     register tptr  tp;
  156.  
  157.     for( tp = tor->tlink; tp != NULL; tp = tp->scache.t )
  158.       {
  159.         if( tp->scache.t == t )
  160.           {
  161.         tp->scache.t = t->scache.t;
  162.         break;
  163.           }
  164.       }
  165.       }
  166.  
  167.     if( tor->tlink == NULL )
  168.       {
  169.     REPLACE( tor->gate->ngate, tor, t );
  170.     REPLACE( tor->source->nterm, tor, t );
  171.     REPLACE( tor->drain->nterm, tor, t );
  172.     Ffree( tor->r, sizeof( TranResist ) );
  173.     FREE_TRANS( tor );
  174.       }
  175.     else
  176.       {
  177.     register Resists  *ror = tor->r, *r = t->r;
  178.  
  179.     dr = r->rstatic - ror->rstatic;
  180.     ror->rstatic = (ror->rstatic * r->rstatic) / dr;
  181.     dr = r->dynlow - ror->dynlow;
  182.     ror->dynlow = (ror->dynlow * r->dynlow) / dr;
  183.     dr = r->dynhigh - ror->dynhigh;
  184.     ror->dynhigh = (ror->dynhigh * r->dynhigh) / dr;
  185.  
  186.     if( t->ttype & ALWAYSON )
  187.       {
  188.         CONNECT( on_trans, t );
  189.       }
  190.     else
  191.       {
  192.         CONNECT( t->gate->ngate, t );
  193.       }
  194.     if( not (t->source->nflags & POWER_RAIL) )
  195.       {
  196.         CONNECT( t->source->nterm, t );
  197.       }
  198.     if( not (t->drain->nflags & POWER_RAIL) )
  199.       {
  200.         CONNECT( t->drain->nterm, t );
  201.       }
  202.       }
  203.     t->ttype &= ~ORLIST;
  204.     nored[ BASETYPE( t->ttype ) ] -= 1;
  205.   }
  206.  
  207.  
  208. public int pParallelTxtors()
  209.   {
  210.     int  i, any;
  211.  
  212.     lprintf( stdout, "parallel txtors:" );
  213.     for( i = any = 0; i < NTTYPES; i++ )
  214.       {
  215.     if( nored[i] != 0 )
  216.       {
  217.         lprintf( stdout, " %s=%d", ttype[i], nored[i] );
  218.         any = TRUE;
  219.       }
  220.       }
  221.     lprintf( stdout, "%s\n", (any) ? "" : "none" );
  222.   }
  223.